package com.itcoon.demo.web.controller.transform;/**
 * @author Athric Yu
 * 2024/12/9
 **/

import com.itcoon.cloud.framework.transform.Transformer;
import com.itcoon.cloud.framework.webmvc.response.ApiResponse;
import com.itcoon.demo.web.controller.transform.pojo.ComplexTypeVariableReqDemo;
import com.itcoon.demo.web.controller.transform.pojo.EmployeeDO;
import com.itcoon.demo.web.controller.transform.pojo.TypeVariableReqDemo;
import com.itcoon.demo.web.controller.transform.pojo.TypeVariableRespDemo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl;

import java.lang.reflect.Type;
import java.util.List;

/**
 *
 *
 * @author Athric Yu
 * 2024/12/9
 **/
@Tag(name = "TRANSFORM")
@RequestMapping("/transforms/type-variables")
@RestController
public class TypeVariableController {

    @PostMapping
    @Operation(summary = "测试TypeVariable")
    public ApiResponse<TypeVariableRespDemo<String, EmployeeDO>> variable(@RequestBody TypeVariableReqDemo demo){
        return ApiResponse.ok(Transformer.to(TypeVariableRespDemo.class, String.class, EmployeeDO.class).apply(demo).convert());
    }

    @PostMapping("/ignore")
    @Operation(summary = "测试TypeVariable, 参数缺省传递泛型")
    public ApiResponse<TypeVariableRespDemo<String, EmployeeDO>> variable2(@RequestBody TypeVariableReqDemo demo){
        return ApiResponse.ok(Transformer.to(TypeVariableRespDemo.class).apply(demo).convert());
    }

    @PostMapping("/complex")
    @Operation(summary = "测试复杂TypeVariable")
    public ApiResponse<TypeVariableRespDemo<String, EmployeeDO>> variable3(@RequestBody ComplexTypeVariableReqDemo demo){
        return ApiResponse.ok(Transformer.to(TypeVariableRespDemo.class, ParameterizedTypeImpl.make(List.class, new Type[]{String.class}, null), EmployeeDO[].class).apply(demo).convert());
    }
}
